<template>
  <el-form>
    <el-form-item label="原密码">
      <el-input v-model="changePasswordObj.oldPassword" />
    </el-form-item>
    <el-form-item label="新密码">
      <el-input v-model="changePasswordObj.newPassword" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="updatePassword">修改</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { updatePassword } from '@/api/user'

export default {
  name: 'ChangePassword',
  data() {
    return {
      changePasswordObj: {}
    }
  },
  methods: {
    updatePassword() {
      this.$confirm('请确认是否修改密码？', '修改密码', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        const changePasswordObj = this.changePasswordObj
        changePasswordObj.userId = this.$store.getters.id
        updatePassword(changePasswordObj).then(res => {
          if (res.code === 20000) {
            this.$message.success(res.message)
          } else {
            this.$message.error(res.message)
          }
        })
      })
    }
  }
}
</script>
